#include "app/myapp.h"

#include <QDebug>


#include "database_plugins/idatabase.h"

#include "app/sslserver.h"
#include "core/core.h"

int main(int argc, char *argv[]){
#ifdef Q_WS_X11
	bool useGUI = getenv("DISPLAY") != 0;
#else
	bool useGUI = true;
#endif


	MyApp a(argc, argv, useGUI);






	qDebug()<<"Application PID:"<<a.applicationPid();
#ifdef Q_WS_WIN
	IDatabase *plugin = qobject_cast<IDatabase*>
								(Core::instance()->database("postgresql.dll"));
#elif defined Q_WS_MAC
	IDatabase *plugin = qobject_cast<IDatabase*>
							(Core::instance()->database("libpostgresql.dylib"));
#else
	IDatabase *plugin = qobject_cast<IDatabase*>
							(Core::instance()->database("libpostgresql.so"));
#endif
	if( plugin && plugin->canConnect() ){
		plugin->init( Core::instance() );
		plugin->connectToDB();
	}


	int port = 443;
	SSLServer server;
	if(!server.listen(QHostAddress::Any, port))
		qDebug("Listening on port %i. Please press Ctrl-C to exit.", port);

	return a.exec();
}
